#ifndef __BSP_CONFIG_PARAM_H__
#define __BSP_CONFIG_PARAM_H__

#include "stdint.h"

#define STORAGE_NAMESPACE "storage"

#define TIMES_OF_MEDICINE 400 //  灭蚊药液可以用400次
#define HOURS_OF_REPEL 300    //  驱蚊药液可以用300小时

#define P 1
#define I 1
#define D 1

#define SELF_TUNING_FLAG 1

#define TARGET_TEMP 190

#define PUMP_COUNTER 0   //正常为0
#define MEDICINE_TYPE NORMAL_MEDICINE
#define EMPTY_OR_NOT NOT_EMPTY
#define EVACUATE_OR_NOT NOT_NEED_EVACU

#define BACK_LIGHT 2

#define SOUNG_MODE BUZZER_ON
// #define WIFI_BLE_MODE WIFI_ON


#define WORKING_MODE ENUM_FUMIGATE_ENCHANCE_MODE
#define FUMIGATE_BUF_MODE ENUM_FUMIGATE_ENCHANCE_MODE
#define REPEL_BUF_MODE ENUM_REPEL_MATERNAL_MODE

#define WORKING_STATUS ENUM_WORKING_STOP

#define FUMI_HOUSE_HEIGHT 3.0
#define FUMI_AREA ENUM_80_100_M2_F

#define REPEL_SETT_MODE ENUM_MOS_REPEL_NORMAL

#define REPEL_TIME_START_HOUR 0
#define REPEL_TIME_END_HOUR 0

#define REPEL_AREA_ENUM_MODE ENUM_21_30_M2

#define WIFI_MODE WIFI_CONNECT

/*****************结构体的键名*********************/
#define WORKING_MODE_KEY "work_mode"
#define WORKING_STATUS_KEY "work_stat"
#define FUMIGATE_SETT_KEY "fumi_sett"
#define REPELLENT_SETT_KEY "repel_sett"
#define FACTORY_SETT_KEY "fact_sett"
#define BOOLEAN_KEY "sound"
#define PUMPCNT_KEY "pucnt"
#define PID_PARAM_KEY "pid_par"
#define MQTT_PARAM_KEY "mqtt_par"

enum mode //工作模式
{
    ENUM_FUMIGATE_NORMAL_MODE,   //正常熏蒸模式
    ENUM_FUMIGATE_ENCHANCE_MODE, //增强熏蒸模式
    ENUM_REPEL_AIR_CONDI_MODE,   //空调驱蚊模式
    ENUM_REPEL_MATERNAL_MODE,    //母婴驱蚊模式
    ENUM_REPEL_ENCHANCE_MODE,    //增强驱蚊模式
    ENUM_AROMA_MODE,             //正常模式被替换为了香薰模式
};

struct work_mode
{
    enum mode working_mode;
    enum mode fumigate_buf_mode; //存储熏蒸时的模式  便于记忆
    enum mode repel_buf_mode;    //存储驱蚊时的模式  便于记忆
};

typedef struct
{
    struct work_mode work_mode_data;
    char *pC;        //存储键值用的
    uint32_t length; //存储结构体的长度
} WORKING_MODE_Typedef;
/*************************************************/

/*************************************************/
enum status
{
    ENUM_WORKING_STOP,  //工作停止
    ENUM_WORKING_READY, //
    ENUM_WORKING_WAIT,  //等待工作
    ENUM_WORKING_START, //工作开始
    ENUM_FAN_WORKING,   //工作中
    ENUM_STATUS_ALL,
}; //

typedef struct
{
    enum status working_status_data;
    char *pC;        //存储键值用的
    uint32_t length; //存储结构体的长度
} WORKING_STATUS_Typedef;
/*************************************************/

/*************************************************/
enum area_f
{
    ENUM_0_15_M2_F,
    ENUM_15_30_M2_F,
    ENUM_30_50_M2_F,
    ENUM_50_80_M2_F,
    ENUM_80_100_M2_F,
    ENUM_100_150_M2_F,
    ENUM_150_200_M2_F,
    ENUM_M2_F
};

struct fumigate_sett
{
    float fumi_house_height;
    enum area_f fumi_sett_area;
};

typedef struct
{
    struct fumigate_sett fumi_sett_data;
    char *pC;        //存储键值用的
    uint32_t length; //存储结构体的长度
} FUMIGATE_SETTING_Typedef;
/*************************************************/

/*************************************************/
struct repel_time_sett
{
    uint8_t Start_Hour;
    uint8_t End_Hour;
    bool IsRepeat;
};
enum area_e
{
    ENUM_BENEATH_10M2,
    ENUM_10_20_M2,
    ENUM_21_30_M2,
    ENUM_M2_ALL
};
enum repel_sett
{
    ENUM_MOS_REPEL_NORMAL,
    ENUM_MOS_REPEL_TIMING,
};

struct repel_setts
{
    enum repel_sett repel_sett_mode;
    struct repel_time_sett repel_sett_timing;
    enum area_e repel_sett_area;
    uint8_t backlight;
    volatile uint32_t total_repel_time;
};

typedef struct
{
    struct repel_setts repel_sett_data;
    char *pC;                //存储键值用的
    uint32_t length;         //存储结构体的长度
} REPELLENT_SETTING_Typedef; //11byte
/*************************************************/

/*************************************************/
struct factory_sett
{
    uint16_t evacuation_times;     //2byte
    uint16_t fumigate_time;        //2byte
    float timers_per10m3;          //4byte
    uint16_t air_condi_open_time;  //2byte
    uint16_t air_condi_close_time; //2byte
    uint16_t maternal_open_time;   //2byte
    uint16_t maternal_close_time;  //2byte
    uint16_t normal_open_time;     //2byte
    uint16_t normal_close_time;    //2byte
    uint16_t area10m2_factory;     //2byte
    uint16_t area20m2_factory;     //2byte
    uint16_t area30m2_factory;     //2byte
    uint16_t InitRepelTime;        //2byte
};

typedef struct //
{
    struct factory_sett factory_sett_data;
    char *pC;           //存储键值用的
    uint32_t length;    //存储结构体的长度
} FACTORY_SETT_Typedef; //2*14+2=30byte
/*************************************************/

/*************************************************/
enum sound
{
    BUZZER_ON,
    BUZZER_OFF,
};

// enum WIFI_OR_BLE
// {
//     WIFI_ON,    //WIFI开启,BLE关闭
//     TRANSIENT_STATE, //中间态
//     BLE_ON,      //BLE开启,WIFI关闭
//     WIFI_BLE_ALL
// };

/**
 *  多用途结构体 
 */
struct  boolean_struct
{
    enum sound sound_status_data; //1byte
    // enum WIFI_OR_BLE wifi_or_ble;
};

typedef struct
{
    struct  boolean_struct boolean_struct_data;
    char *pC;                     //存储键值用的
    uint32_t length;              //存储结构体的长度
} BOOLEAN_Typedef;
/*************************************************/

/*************************************************/
enum medicine_type
{
    NORMAL_MEDICINE,
    MEDIAN_MEDICINE,
    ENCHANCE_MEDICINE,
    ALL_MEDICINE,
};
enum is_empty_
{
    IS_EMPTY,
    NOT_EMPTY,
    ALL_EMPTY,
};
enum need_evacua
{
    NEED_EVACU,
    NOT_NEED_EVACU,
};

struct pump_cnt
{
    uint32_t pumpcnt;                 //4byte
    enum need_evacua need_evacuation; //1byte
    enum is_empty_ is_empty;          //1byte
    enum medicine_type type;          //1byte
};

typedef struct
{
    struct pump_cnt pump_cnt_data;
    char *pC;        //存储键值用的
    uint32_t length; //存储结构体的长度
} PUMPCNT_Typedef;   //7byte
/*************************************************/

/*************************************************/
struct pid_param
{
    float SetPoint;
    float SetPointBackup;
    float Proportion;
    float Integral;
    float Derivative;
    uint8_t Self_Tuning_Flag;
};

typedef struct
{
    struct pid_param pid_param_data;
    char *pC;        //存储键值用的
    uint32_t length; //存储结构体的长度
} PID_Param_Typedef;
/*************************************************/

/*************************************************/
enum scan_connect
{
    WIFI_SCANNING, //WIFI配网模式
    WIFI_CONNECT,  //WIFI连接模式
};

struct mqtt_param
{
    char wifi_ssid[32];
    char wifi_password[64];
    uint16_t wifi_maximum_retry; //最大重连次数
    enum scan_connect wifi_mode; //当前wifi的模式
    char mqtt_topic[25];
};

typedef struct
{
    struct mqtt_param mqtt_param_data;
    char *pC;        //存储键值用的         长度和key很重要
    uint32_t length; //存储结构体的长度
} MQTT_Param_Typedef;
/*************************************************/

typedef struct
{
    WORKING_MODE_Typedef WorkingMode;
    WORKING_STATUS_Typedef WorkingStatus;
    FUMIGATE_SETTING_Typedef FumigateSetting;
    REPELLENT_SETTING_Typedef RepelSetting;
    FACTORY_SETT_Typedef FactorySetting;
    BOOLEAN_Typedef BooleanMode;
    PUMPCNT_Typedef PumpCnt;
    PID_Param_Typedef PID_Param;
    MQTT_Param_Typedef MQTT_Param;
} ConfigParam_Typedef;

extern ConfigParam_Typedef ConfigParam; //这里只需要将默认值赋值给他即可

void ConfigParamInit(void);
void read_config_param(void *pData, void *pChar, void *length);
void write_config_param(void *pData, void *pChar, uint32_t length);

#endif